<template>
  <div class="left-menu">
    <div
      class="left-menu-item"
      :class="{ active: activeLeftMenu === 'form' }"
      @click="changeValue('form')"
    >
      <div class="img-box">
        <img
          v-if="activeLeftMenu === 'form'"
          src="@/assets/img/document-active.png"
          alt=""
          style="width: 20px"
        />
        <img v-else src="@/assets/img/document.png" alt="" style="width: 20px" />
      </div>
      <span style="margin-top: 4px">组件</span>
    </div>
    <div
      class="left-menu-item"
      :class="{ active: activeLeftMenu === 'data' }"
      style="margin-top: 40px"
      @click="changeValue('data')"
    >
      <div class="img-box">
        <img
          v-if="activeLeftMenu === 'data'"
          src="@/assets/img/datasource-active.png"
          alt=""
          style="width: 20px"
        />
        <img v-else src="@/assets/img/datasource.png" alt="" style="width: 20px" />
      </div>
      <span style="margin-top: 4px">数据</span>
    </div>
  </div>
</template>

<script setup lang="ts">
const emit = defineEmits<{
  'update:modelValue': [string];
  change: [string];
}>();

const props = withDefaults(
  defineProps<{
    modelValue?: string;
  }>(),
  {
    modelValue: 'form',
  },
);

const activeLeftMenu = computed(() => {
  return props.modelValue;
});

const changeValue = (value: string) => {
  emit('update:modelValue', value);
  emit('change', value);
};
</script>

<style lang="scss" scoped>
.form-design .left-menu {
  width: 48px;
  height: 100%;
  padding: 23px 0;
  background: #2d3039;
}
.form-design .left-menu .left-menu-item {
  display: flex;
  align-items: center;
  font-size: 14px;
  text-align: center;
  color: white;
  color: #a4a5a7;
  flex-direction: column;
  justify-items: center;
  font-weight: 400;
  cursor: pointer;
}
.form-design .left-menu .left-menu-item.active {
  color: $color-primary;
}
.active {
  .img-box {
    background-color: $color-primary;
  }
}
.img-box {
  display: flex;
  justify-content: center;
  padding: 5px;
  border-radius: 4px;
  img {
    vertical-align: middle;
  }
}
</style>
